﻿using NET6.WebAPI.Enums;
using NET6.WebAPI.Extensions;

namespace NET6.WebAPI.Dtos.Tool
{
    /// <summary>
    /// 接口输出模型
    /// </summary>
    public class HttpResponseDto
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 说明
        /// </summary>
        public string Explain { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        public object Result { get; set; }

        public HttpResponseDto(HttpResponseCode value)
        {
            Code = value.ToInt();
            Success = value.GetBoolValue();
            Explain = value.GetDescription();
        }

        public HttpResponseDto(ExceptionResponseCode value)
        {
            Code = value.ToInt();
            Success = value.GetBoolValue();
            Explain = value.GetDescription();
        }

        public HttpResponseDto(HttpResponseCode value, object result)
        {
            Code = value.ToInt();
            Success = value.GetBoolValue();
            Explain = value.GetDescription();
            Result = result;
        }
    }
}
